package com.probiz.estoremf.customer.web.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.customer.Customer;
import com.probiz.estore.common.model.customer.ShopPointHistory;
import com.probiz.estore.core.controller.GenericCustomerFrontController;
import com.probiz.estore.core.search.SearchCriteria;
import com.probiz.estore.customer.service.CustomerManager;
import com.probiz.estore.customer.service.MembershipManager;
import com.probiz.estore.customer.service.ShopPointHistoryManager;
import com.probiz.estore.customer.service.ShopPointManager;
import com.probiz.estore.webapp.util.RequestContext;

public class CsShopPointFrontController extends GenericCustomerFrontController<ShopPointHistory> {

	private ShopPointHistoryManager	shopPointHistoryManager	= null;
	private ShopPointManager		shopPointManager		= null;
	private MembershipManager		membershipManager		= null;
	private CustomerManager		customerManager		= null;
	
	public void setShopPointHistoryManager(ShopPointHistoryManager shopPointHistoryManager) {
		this.shopPointHistoryManager = shopPointHistoryManager;
	}

	public void setShopPointManager(ShopPointManager shopPointManager) {
		this.shopPointManager = shopPointManager;
	}

	public void setMembershipManager(MembershipManager membershipManager) {
		this.membershipManager = membershipManager;
	}

	public void setCustomerManager(CustomerManager customerManager) {
		this.customerManager = customerManager;
	}

	@Override
	protected String getEntityName(ShopPointHistory entity) {
		return null;
	}
	
	@Override
	protected void preSave(HttpServletRequest request, ShopPointHistory entity,
			BindException errors) {
		
	}

	@Override
	protected Map<Integer, Map<String, Object>> getMultiSaveModel(HttpServletRequest request) {
		return null;
	}

	@Override
	protected void initController() throws Exception {
		super.mgr = shopPointHistoryManager;
	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.core.controller.GenericCustomerFrontController#defaultAction(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	public ModelAndView defaultAction(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/csShopPoint");
		Customer customer = customerManager.getByAppUserId(RequestContext.getCurrentUserId());
		mv.addObject("customer", customer);
		mv.addObject("nextLevelMembership", membershipManager.getHigherLevelMembership(customer.getMembership().getMembershipLevel()));
		mv.addObject("membershipList", membershipManager.getAllMembershipsOrderByLevel(true));
		
		SearchCriteria sc = createSearchCriteria(request, ShopPointHistory.FilterHqlName.MY_HISTORY_LIST);
		sc.removeParamValues();
		sc.addParamValue(RequestContext.getCurrentUserId());
		List<ShopPointHistory> shopPointHistoryList = this.searchByCriteria(sc);
		mv.addObject("shopPointHistoryList", shopPointHistoryList);
		return mv;
	}
}
